package com.xunyin.nettyV.client;


import com.alibaba.fastjson.JSON;
import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
import org.eclipse.paho.client.mqttv3.MqttMessage;

/**
 * @Author xunyinyunshang  <3594419785@qq.com>
 * @date 2023-3-16
 * mqtt客户端订阅监听
 */
public class SubMessageListener implements IMqttMessageListener {

    @Override
    public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
        System.out.println("接收消息主题 : " + topic);
        System.out.println("接收消息Qos : " + mqttMessage.getQos());
        System.out.println("接收消息内容 : " + new String(mqttMessage.getPayload()));
        com.alibaba.fastjson.JSONObject jsonPayloadObject = JSON.parseObject(new String(mqttMessage.getPayload()));
        // 硬件物理地址
        String mac = jsonPayloadObject.getString("mac");
/*         JSONObject reBasicDown = new JSONObject();
                    reBasicDown.put("mac",mac);
                    reBasicDown.put("relay",0);
                    reBasicDown.put("time", DateUtils.parseDate2String(new Date(), "yyyy-MM-dd HH:mm:ss"));
                    reBasicDown.put("reboot",0);
                    reBasicDown.put("ip", MqConfig.ip);
                    reBasicDown.put("port", MqConfig.port);
                    // 给硬件发送消息-前提是硬件订阅这主题
                    PubMsg.publish(reBasicDown.toJSONString(), "client-id-0", "/dev/"+mac+"/basic/down");*/
    }

}
